# Use node:18-alpine as the base image for the build stage
FROM node:18-alpine AS build

# Install necessary dependencies
RUN apk add --no-cache libgcc musl-dev

# Set the working directory
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Set npm registry (optional, for faster installations in some regions)
RUN npm config set registry https://registry.npmmirror.com/

# Install dependencies
RUN yarn

# Copy all source code into the container
COPY . .

# Build the application
RUN npm run build

# Use nginx:alpine as the base image for the final stage
FROM nginx:alpine AS final

# Add metadata to the image
LABEL maintainer="HeartAI Team" \
      version="1.0" \
      description="HeartAI Web Application"

# Copy the built files from the build stage to the nginx HTML directory
COPY --from=build /app/dist /usr/share/nginx/html

# Copy the custom nginx configuration file
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Expose port 80
EXPOSE 80